package github.sf.fw.model;

import lombok.Data;

import java.util.*;

/**
 * 图标数据
 *
 * @author zhoup
 */
@Data
public class ChartData {
    /**
     * 标签
     */
    Map<String, String> tags = new LinkedHashMap<>();
    /**
     * 日期
     */
    List<Date> dates = new ArrayList<>();
    /**
     * 横坐标
     */
    long[] abscissa = new long[0];
    /**
     * 纵坐标
     */
    double[] ordinate = new double[0];

    private int capacity = 0;
    private transient int cursor = 0;

    public ChartData() {
    }

    public ChartData(int capacity) {
        dates = new ArrayList<>(capacity);
        abscissa = new long[capacity];
        ordinate = new double[capacity];
        this.capacity = capacity;
    }

    public void addAbscissa(long abscissaData) {
        if (cursor < abscissa.length) {
            abscissa[cursor++] = abscissaData;
        }
    }

    public void addOrdinate(double ordinateData) {
        if (cursor < ordinate.length) {
            ordinate[cursor++] = ordinateData;
        }
    }

    public void addDate(Date date) {
        if (cursor < capacity) {
            dates.add(date);
        }
    }

    public void putTag(String key, String value) {
        tags.put(key, value);
    }
}
